package day5.homework4;

public class ATM {
    public Integer sum = 0;// 累计取款金额
    public Integer residueLimit = 10000; // 剩余每日限额
    private int balance; // 余额


    public void menu() {
        System.out.println("1. 存款");
        System.out.println("2. 取款");
        System.out.println("3. 查询余额");
        System.out.println("0. 退出");
    }

    public boolean login(String password) {
        return "123456".equals(password);
    }

    public boolean deposit(int operateMoney) {
        if (operateMoney % 100 != 0) return false;
        balance += operateMoney;
        return true;
    }

    public Result withdrawMoney(int operateMoney) {
        if (operateMoney % 100 != 0) return Result.FAIL;
        // 取款金额不允许超过余额
        if (operateMoney > balance) return Result.FAIL_LESS_BALANCE;
        // 限额已经为0或者负数了
        if (residueLimit <= 0) return Result.FAIL_LESS_LIMIT;
        // 扣除限额的金额
        residueLimit = residueLimit - operateMoney;
        if (residueLimit >= 0) {
            balance -= operateMoney;
            sum += operateMoney; // 保存累计
            return Result.SUCCESS;
        }
        // 获取实际能取的钱 假设限额还有1000，这个时候取款5000.
        int realMoney = operateMoney + residueLimit;
        balance-= realMoney; // 扣除实际取款金额
        sum += realMoney; // 保存累计
        return Result.SUCCESS_SECTION;
    }

    public Integer query() {
        return balance;
    }

}
